package com.livegoods.service.impl;

import com.livegoods.pojo.House;
import com.livegoods.pojo.LivegoodsResult;
import com.livegoods.service.DetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Duration;

@Service
public class DetailsServiceImpl implements DetailsService {

    @Value("${livegoods.fastdfs.nginx}")
    private String nginxHost;

    @Autowired
    private MongoTemplate mongoTemplate;



    @Cacheable(cacheNames = "com.livegoods",key = "'findById'+#id")
    public House selectById(String id) {


        System.out.println("没有走缓存");
        try {
            House house = mongoTemplate.findById(id, House.class);

            String[] imgs = house.getImgs();
            for (int i = 0; i < imgs.length; i++) {
                imgs[i] = nginxHost+imgs[i];
            }

            house.setImgs(imgs);

            return house;
        } catch (Exception e) {
            return null;
        }
    }
}
